class Solution:
    def getMaxLen(self, nums: list) -> int:
        pos = 0
        neg = 0
        if nums[0] > 0:
            pos = 1
        elif nums[0] < 0:
            neg = 1
        res = pos
        for i in range(1, len(nums)):
            preNeg = neg
            if nums[i] > 0:
                if nums[i - 1] > 0:
                    pos += 1
                    if neg > 0:
                        neg += 1
                elif nums[i - 1] < 0:
                    if pos > 0:
                        pos += 1
                    else:
                        pos = 1
                    neg += 1
                else:
                    pos = 1
                    neg = 0
            elif nums[i] < 0:
                if nums[i - 1] != 0:
                    if pos > 0:
                        neg = pos + 1
                    else:
                        neg = 1
                    if preNeg > 0:
                        pos = preNeg + 1
                    else:
                        pos = 0
                else:
                    pos = 0
                    neg = 1

            res = max(res, pos)
        return res
